package com.yoke.util;
/**
 * Created by jiangzeyin on 2017/2/16.
 */

import java.io.*;

/**
 * @author jiangzeyin
 * @create 2017 02 16 10:52
 */
public class FileUtil {

    /**
     * 追加文件内容
     *
     * @param fileName
     * @param content
     * @param append   是否是追加
     * @throws IOException
     * @author jiangzeyin
     * @date 2016-8-11
     */
    public static void appendFileContext(String fileName, String content, boolean append) throws IOException {
        File file = new File(fileName);
        file.getParentFile().mkdirs();
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8"));
        out.write(content);
        out.close();
    }

    public static String clearPath(String input) {
        input = input.replace('\\', '/');
        return clearPath_(input);
    }

    private static String clearPath_(String input) {
        int from = 0;
        int j = input.indexOf("://");
        if (j != -1) {
            from = j + 3;
        }
        int i = input.indexOf("//", from);
        if (i == -1) {
            return input;
        }

        String input_ = input.substring(0, i) + "/" + input.substring(i + 2);
        return clearPath_(input_);
    }
}
